

package com.desksoft.ecommerce.util.NoticeHelp;

import java.io.UnsupportedEncodingException;

import javax.mail.BodyPart;
import javax.mail.MessagingException;
import javax.mail.internet.MimeUtility;

import com.desksoft.ecommerce.util.holder.ApplicationContextHolder;
import com.desksoft.utility.mail.MailService;
import com.desksoft.utility.mail.message.MailMessage;

/***************************************
 * 
 * <pre>
 * 版权所有：杭州迪科软件 保留所有权利
 * 创建日期: 2013-8-19 下午02:03:49
 * 创建作者：jianghao
 * 文件名称：EmailThread.java
 * 版本：
 * 功能：
 * 最后修改时间：2013-8-19
 * 修改记录：
 * </pre>
 **/
public class EmailThread implements Runnable{

	private String emailtext;
	private String title;
	private String[] emailarry;
	public String[] getEmailarry() {
		return emailarry;
	}

	public void setEmailarry(String[] emailarry) {
		this.emailarry = emailarry;
	}

	public String getEmailtext() {
		return emailtext;
	}

	public void setEmailtext(String emailtext) {
		this.emailtext = emailtext;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Override
	public void run() {

		try {
			MailService mailService = (MailService) ApplicationContextHolder.getBean("mailService");
			MailMessage mailMessage = new MailMessage("utf-8");
			BodyPart contentPart = mailMessage.createHtmlPart(emailtext);
			contentPart.setContent(emailtext, "text/html;charset=utf-8");
		//	contentPart.setText(emailtext);
			mailMessage.appendMailPart(contentPart);
			mailMessage.setBody(emailtext);
			mailMessage.setSubject(MimeUtility.encodeText( title,"gb2312","B"));
			mailService.sendMessage(mailMessage, emailarry);
		} catch (MessagingException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}

}
